﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Tomahawk.Runtime.Canvas.Sprite
{
    public class UISpriteRenderer : SpriteRenderer
    {
        /// <summary>
        /// Rendering the UI Sprites
        /// </summary>
        public override void Render()
        {
            base.Render();

            foreach (SpriteRenderBatch batch in spriteBatches)
            {
                //Find the effect to use
                SpriteEffect effect = Engine.Instance.CanvasManager.GetEffectAssignedToChannel(batch.spriteEffect);

                //Prepare the sprite batch
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);

                //Prepare the sprite effect
                if (effect != null)
                {
                    effect.Begin();
                }

                //render all uisprites
                foreach (Sprite sprite in batch.sprites)
                {
                    if (sprite.Visible)
                    {
                        sprite.Render(this.spriteBatch);
                    }
                }

                //end the spritebatch
                spriteBatch.End();

                //end the sprite effect
                if (effect != null)
                {
                    effect.End();
                }
            }
        }

    }
}
